<template>
	<view class="page">
		<view class="input">
			<view class="text">当前头像：</view>
			<view class="head-img"><image :src="userInfo.head_pic_text"></image></view>
		</view>
		<view class="upload-img">
		    <view class="publish-upload" @tap="choose_image">
		    	<image v-if="imageList.temp" :src="imageList.temp"></image>
		    </view>
		</view>
		<button class="u-confirm" @tap="confirm">提交</button>
	</view>
</template>

<script>
	import henglang from '@/common/common.js';
	export default {
		data() {
			return {
				userInfo:{},
				imageList:{
					'temp':'',
					'url':''
				},
				token:''
			};
		},
        methods:{
            confirm() {
				henglang.showToast('修改成功！')
				uni.redirectTo({
					url:'/pages/user/settings/set_index'
				})
            },
			choose_image(){
				let that = this;
				uni.chooseImage({
					sourceType: ['album', 'camera'],
					sizeType: ['original', 'compressed'],
					count: 1,
					success: (res) => {
						let filePath = res.tempFilePaths[0];
						uni.uploadFile({
							url: henglang.host + 'member/modifyMemberHead',
							fileType: 'image',
							filePath: filePath,
							name: 'head_pic',
							header:{
								'app-key': henglang.app_key,
								'access-token': that.token
							},
							success: (uploadFileRes) => {
								let data = uploadFileRes.data;
								data = JSON.parse(data);
								if(data.code == 0) {
									that.imageList.temp = filePath
									that.imageList.url = data.data.url
								}else{
									henglang.showToast(data.msg, 1500);
								}
								
							}
						});
					}
				})
			}
        },
		onLoad({type}) {
			this.type = type
			this.userInfo = uni.getStorageSync('userInfo');
			this.token = uni.getStorageSync('token');
		}
	}
</script>

<style>
    .page {
        background: #f5f5f5;
    }
    .head-img image{
		border-radius: 50%;
		overflow: hidden;
		width: 100rpx;
		height: 100rpx;
		display: block;
	}
	.input{
		padding: 20upx;
		display: flex;
		align-items: center;
	}
	.upload-img{
		background: #FFFFFF;
		display: flex;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.upload-img .publish-upload{
		width: 180rpx;
		height: 180rpx;
		border: 1px solid #e6e6e6;
		background: #F5F5F5;
		border-radius: 5px;
		text-align: center;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;
	}
	.upload-img .publish-upload:after{
		content: '';
		position: absolute;
		background-image: url('~@/static/icons/plus.png');
		background-repeat: no-repeat;
		background-size: 60rpx 60rpx;
		background-position: center center;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: -1;
	}
	.upload-img .publish-upload image{
		width: 100%;
		height: 100%;
		display: block;
		margin: 0 auto;
	}
	.u-confirm{
		width: 90%;
		margin: 60upx 0 0 5%;
		border-radius: 100px;
		background: #d71311;
		color: #fff;
		text-align: center;
		padding: 30upx;
		font-size: 38upx;
	}
</style>
